#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "all.h"
#define MAX  30   //宏定义最大学生人数
//定义全局变量
int num=0; //定义学生编号
int x=0;  //定义浏览学生信息的个数c 
//定义全局变量
int num1=0; //定义课程编号
int x1=0;  //定义浏览课程信息的个数c 
int main(int argc, char const *argv[])//主函数
{
  th_note *ab =(struct student*)malloc(sizeof(struct student)*100);
  th_note1 *a =(struct studentclass*)malloc(sizeof(struct studentclass)*100);
  int i;
  start:
  printf("\n\t\t\t欢迎使用学生选课系统!\n");
  printf("菜单:\n");
  printf("1.增加学生数据\n");
  printf("2.删除学生数据\n");
  printf("3.查询学生数据\n");
  printf("4.修改学生数据\n");
  printf("5.增加课程数据\n");
  printf("6.删除课程数据\n");
  printf("7.查询课程数据\n");
  printf("8.修改课程数据\n");
  printf("9.退出系统\n");
  printf("\n请输入菜单选项(1~9):\n");
  scanf("%d",&i);
  if(i<1 || i>9)
  {
    printf("输入错误,请重输:\n");
    goto start;
  }
  switch(i)
  {
  case(1):
    {
      system("cls");
      add(ab);
      //inputc();
      goto start;
      break;
    }
  case(2):
    {
      system("cls");
      deletel(ab);
      goto start;
      break;
    }
  case(3):
    {
      system("cls");
      inquire(ab);
      void inquire(th_note *ab);
      goto start;
      break;
    }
  case(4):
    {
      system("cls");
      amend(ab);
      goto start;
      break;
    }
 case(5):
    {
      system("cls");
      //inputc1();
      addclass(a);
      goto start;
      break;
    }
 case(6):
    {
      system("cls");
      deletelclass(a);
      goto start;
      break;
    }
  case(7):
    {
      system("cls");
      inquireclass(a);
      goto start;
      break;
    }
  case(8):
    {
      system("cls");
      amendclass(a);
      goto start;
      break;
    }
  case(9):
    {
      system("cls");
      printf("感谢使用本系统!\n\n再见!\n");
    }
  }
  return(0);
}  
/*void inputc()//录入课程主函数
{
  int i;
  printf("\t\t\t增加学生数据\n");
  printf("\n1.从键盘录入\n");
  printf("2.从文件录入\n");
  printf("3.返回主菜单\n");
  printf("请选择(1~3):\n");
  scanf("%d",&i);
  switch(i)
  {
  case(1):add(ab);break;
  case(2):filec();break;
  case(3):break;
  }
}*/

/*-------------------------------------------------
                增加学生数据
-------------------------------------------------*/

void add(th_note *ab)
{
	printf("============================\n");
	printf("请输入你要增加的学生的编号1~%d\n",MAX);
	scanf("%d",&num);
	if(num>0 && num<=MAX)    //判断是否超出学生的最大人数
	{
	    printf("请输入你要增加的学生的姓名\n");
	    scanf("%s",(ab+num)->name);
	    printf("请输入你要增加的学生的学号\n");
	    scanf("%d",&(ab+num)->num);
	    printf("请输入你要增加的学生的已选课程列表\n");
	    scanf("%s",(ab+num)->course);
	    printf("请输入你要增加的学生的已选课程总计学分\n");
	    scanf("%lf",&(ab+num)->score_sel);
	    printf("增加的学生数据:\n编号：%d\t姓名：%s \t学号：%d \t已选课程列表：%s \t已选课程总计学分: %lf\n",
	         num,
            (ab+num)->name,
            (ab+num)->num,
            (ab+num)->course,
            (ab+num)->score_sel
           );
	    x++;
	    printf("增加成功\n"); 
	}
	else
		printf("增加失败\n");
	    printf("\n");
}
/*-------------------------------------------------
                删除学生数据
-------------------------------------------------*/
void deletel(th_note *ab)
{
	printf("============================\n");
	printf("请输入你要删除的学生的编号1~%d\n",MAX);
	scanf("%d",&num);

	if(0<num && num<=MAX)
	{
            strcpy((ab+num)->name,"0");
            strcpy((ab+num)->course,"0");
	    (ab+num)->num='\0';
	    (ab+num)->score_sel='\0';
		
        printf("删除成功！\n");
	}
    else
     printf("删除失败！\n");
     printf("\n");
}
/*-------------------------------------------------
                查询学生数据
-------------------------------------------------*/	

void inquire(th_note *ab)
{
	printf("============================\n");
	printf("请输入你要查询的学生的编号1~%d\n",MAX);
	scanf("%d",&num);
	if(0<num && num<=MAX)
	{
	printf("增加的学生数据:\n编号：%d\t姓名：%s \t学号：%d \t已选课程列表：%s \t已选课程总计学分: %lf\n",
	         num,
	    (ab+num)->name,
            (ab+num)->num,
            (ab+num)->course,
            (ab+num)->score_sel
               );	

	     
	}
    else
     printf("暂无学生信息！\n");
     printf("\n");
}
/*-------------------------------------------------
                修改学生数据
-------------------------------------------------*/
void amend(th_note *ab)
{
	printf("============================\n");
	printf("请输入你要修改的学生的编号1~%d\n",MAX);
	scanf("%d",&num);
	if(0<num && num<=MAX)
	{
           printf("修改学生数据前的学生数据为：\n");
           printf("增加的学生数据:\n编号：%d\t姓名：%s \t学号：%d \t已选课程列表：%s \t已选课程总计学分: %lf\n",num,
            (ab+num)->name,
            (ab+num)->num,
            (ab+num)->course,
            (ab+num)->score_sel
           );
	    printf("请输入你要修改的学生的姓名\n");
	    scanf("%s",(ab+num)->name);
	    printf("请输入你要修改的学生的学号\n");
	    scanf("%d",&(ab+num)->num);
            printf("请输入你要修改的学生的已选课程列表\n");
	    scanf("%s",(ab+num)->course);
            printf("请输入你要修改的学生的已选课程总计学分\n");
	    scanf("%lf",&(ab+num)->score_sel);
            printf("修改学生数据后的学生数据为：\n");
	    printf("编号：编号：%d\t姓名：%s \t学号：%d \t已选课程列表：%s \t已选课程总计学分: %lf\n",num,   
            (ab+num)->name,
            (ab+num)->num,
            (ab+num)->course,
            (ab+num)->score_sel
           );  
	     
	}
    else
     printf("暂无学生信息,无法修改！\n");
     printf("\n");
}
/*void inputc1()//录入课程主函数
{
  int i;
  printf("\t\t\t增加学生数据\n");
  printf("\n1.从键盘录入\n");
  printf("2.从文件录入\n");
  printf("3.返回主菜单\n");
  printf("请选择(1~3):\n");
  scanf("%d",&i);
  switch(i)
  {
  case(1):addclass(a);break;
  case(2):filec();break;
  case(3):break;
  }
}*/
/*-------------------------------------------------
                增加课程数据
-------------------------------------------------*/
void addclass(th_note1 *a)
{
	printf("============================\n");
	printf("请输入你要增加的课程的编号1~%d\n",MAX);
	scanf("%d",&num1);
	if(num1>0 && num1<=MAX)    //判断是否超出课程的最大数量 
	{
	    printf("请输入你要增加的课程名称\n");
	    scanf("%s",(a+num1)->classname);
	    printf("请输入你要增加的课程性质\n");
	    scanf("%s",(a+num1)->classnature);
	    printf("请输入你要增加的课程学时\n");
	    scanf("%d",&(a+num1)->classtime);
	    printf("请输入你要增加的课程学分\n");
	    scanf("%d",&(a+num1)->classscore);
	    printf("请输入你要增加的课程已选人数\n");
	    scanf("%d",&(a+num1)->nelepeo);
	    printf("请输入你要增加的课程人数上限\n");
	    scanf("%d",&(a+num1)->melepeo);
	    printf("增加的课程数据:\n编号：%d\t课程名称: %s\t课程性质: %s\t课程学时: %d\t课程学分: %d\t课程已选人数: %d\t课程人数上限: %d\t\n",
	         num1,
            (a+num1)->classname,
            (a+num1)->classnature,
            (a+num1)->classtime,
            (a+num1)->classscore,
            (a+num1)->nelepeo,
            (a+num1)->melepeo
           );
	    x1++;
	    printf("增加成功\n"); 
	}
	else
		printf("增加失败\n");
	    printf("\n");
}

/*-------------------------------------------------
                删除课程数据
-------------------------------------------------*/
void deletelclass(th_note1 *a)
{
	printf("============================\n");
	printf("请输入你要删除的课程的编号1~%d\n",MAX);
	scanf("%d",&num1);

	if(0<num1 && num1<=MAX)
	{
	    strcpy((a+num1)->classnature,"0");
	    strcpy((a+num1)->classname,"0");
	    (a+num1)->classtime='\0';
	    (a+num1)->classscore='\0';
	    (a+num1)->nelepeo='\0';
	    (a+num1)->melepeo='\0';
		
        printf("删除成功！\n");
	}
    else
     printf("删除失败！\n");
     printf("\n");
}
/*-------------------------------------------------
                查询课程数据
-------------------------------------------------*/	

void inquireclass(th_note1 *a)
{
	printf("============================\n");
	printf("请输入你要查询的课程的编号1~%d\n",MAX);
	scanf("%d",&num1);
	if(0<num1 && num1<=MAX)
	{
	printf("增加的课程数据:\n编号：%d\t课程名称: %s\t课程性质: %s\t课程学时: %d\t课程学分: %d\t课程已选人数: %d\t课程人数上限: %d\t\n",
	         num1,
            (a+num1)->classname,
            (a+num1)->classnature,
            (a+num1)->classtime,
            (a+num1)->classscore,
            (a+num1)->nelepeo,
            (a+num1)->melepeo
               );	
	     
	}
    else
     printf("暂无学生信息！\n");
     printf("\n");
}
/*-------------------------------------------------
                修改课程数据
-------------------------------------------------*/
void amendclass(th_note1 *a)
{
	printf("============================\n");
	printf("请输入你要修改的课程的编号1~%d\n",MAX);
	scanf("%d",&num1);
	if(0<num1 && num1<=MAX)
	{
		 printf("修改课程数据前的课程数据为：\n");
		 printf("修改的课程数据:\n编号：%d\t课程名称: %s\t课程性质: %s\t课程学时: %d\t课程学分: %d\t课程已选人数: %d\t课程人数上限: %d\t\n",
	         num1,
            (a+num1)->classname,
            (a+num1)->classnature,
            (a+num1)->classtime,
            (a+num1)->classscore,
            (a+num1)->nelepeo,
            (a+num1)->melepeo
           );
	    printf("请输入你要修改的课程名称\n");
	    scanf("%s",(a+num1)->classname);
	    printf("请输入你要修改的课程性质\n");
	    scanf("%s",(a+num1)->classnature);
	    printf("请输入你要修改的课程学时\n");
	    scanf("%d",&(a+num1)->classtime);
	    printf("请输入你要修改的课程学分\n");
	    scanf("%d",&(a+num1)->classscore);
	    printf("请输入你要修改的课程已选人数\n");
	    scanf("%d",&(a+num1)->nelepeo);
	    printf("请输入你要修改的课程人数上限\n");
	    scanf("%d",&(a+num1)->melepeo);
	    printf("修改的课程数据:\n编号：%d\t课程名称: %s\t课程性质: %s\t课程学时: %d\t课程学分: %d\t课程已选人数: %d\t课程人数上限: %d\t\n",
	         num1,
            (a+num1)->classname,
            (a+num1)->classnature,
            (a+num1)->classtime,
            (a+num1)->classscore,
            (a+num1)->nelepeo,
            (a+num1)->melepeo
           );  
	     
	}
    else
     printf("暂无学生信息,无法修改！\n");
     printf("\n");
}

